﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ErrorDialogPageViewModel.cs" company="Microsoft">
//   Microsoft
// </copyright>
// <summary>
//   Defines the ErrorDialogPageViewModel type.
// </summary>
// Copyright (c) Microsoft Corporation. All rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// ----------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
// --------------------------------------------------------------------------------------------------------------------

namespace MySemanticSearch.ViewModel
{
    using System.ComponentModel;
    using System.Windows.Controls;
    using System.Windows.Input;

    using MySemanticSearch.Commands;

    /// <summary>
    /// ViewModel class for the Information dialog page
    /// </summary>
    public class ErrorDialogPageViewModel : INotifyPropertyChanged
    {
        /// <summary>
        /// Reference to the information dialog view
        /// </summary>
        private readonly ChildWindow errorDialogView;

        /// <summary>
        /// Private field that holds the information message
        /// </summary>
        private string informationMessage;

        /// <summary>
        /// Initializes a new instance of the <see cref="ErrorDialogPageViewModel"/> class.
        /// </summary>
        /// <param name="view">
        /// The view argument.
        /// </param>
        public ErrorDialogPageViewModel(ChildWindow view)
        {
            this.errorDialogView = view;
        }

        /// <summary>
        /// Handler to notify when a property has changed
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Gets or sets InformationMessage string.
        /// </summary>
        public string InformationMessage
        {
            get
            {
                return this.informationMessage;
            }

            set
            {
                this.informationMessage = value;
                this.NotifyPropertyChanged("InformationMessage");
            }
        }

        /// <summary>
        /// Gets CloseDialogCommand.
        /// </summary>
        public ICommand CloseDialogCommand
        {
            get
            {
                return new RelayCommand(this.CloseInformationDialog);
            }
        }

        /// <summary>
        /// Method to call after the user clicks OK
        /// </summary>
        public void CloseInformationDialog()
        {
            this.errorDialogView.DialogResult = true;
        }

        #region Notify Property Changed
        /// <summary>
        /// Notify property Changed
        /// </summary>
        /// <param name="info">
        /// The info string.
        /// </param>
        private void NotifyPropertyChanged(string info)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        #endregion
    }
}
